package com.dyh.quickdemo.trace;

import org.springframework.util.CollectionUtils;

import java.util.Optional;

/*
@Author=Joey Wheeler
@Date=2021/3/9 16:01
*/
public class PrintUtil {

    public static String print(Node node,String clue){
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(node.getTitle()).append("\n");
        if (CollectionUtils.isEmpty(node.getClues()))
            return stringBuffer.toString();
        Clue target = node.getClues().stream().filter(e->clue.equals(e.getTitle()))
                .findFirst().get();
        stringBuffer.append(target.getTitle()).append("\n");
        if (CollectionUtils.isEmpty( target.reference()))
            return stringBuffer.toString();
        for (Node refNode : target.reference()) {
            stringBuffer.append(print(refNode,clue)).append("\n");
        }
        return stringBuffer.toString();
    }
}
